package collections;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;

/**
 * Created by pc on 2015/2/16.
 * 提供了一个listIterator方法，比普通iterator增加了向前遍历与添加元素的功能* 
 */
public class ArrayListDemo {
    public static void main(String args[]){
        List<String> aList = new ArrayList<String>();
        aList.add("北京");
        aList.add("深圳");
        aList.add("广州");

        String [] sArr = aList.toArray(new String[aList.size()]);
        System.out.println(sArr.toString());


        ListIterator<String> it = aList.listIterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
        System.out.println("要先把把游标放在后面才能再往前走，不能一上来就直接往前走");
        while (it.hasPrevious()){
            String tt = it.previous();
            if (tt.equals("深圳")) it.add("南京");
            System.out.println(tt);
        }
        
        //Arrays.ArrayList可以修改，但是长度固定
        List<String> bList = Arrays.asList("a", "b", "c");
        bList.set(0, "aaaa");
        System.out.println(bList);
    }
    
}
